﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using RuleCode.Table;
namespace chatblog
{
    public partial class catalist : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                cbuser.dealcookie();
                dealrequest();
                bind1();
                //bind2();
                //bind3();
            }
        }
        /// <summary>
        /// 绑定
        /// </summary>
        private void bind1()
        {
            cbusercata uc = cbusercata.Find(" cbuserid = '" + AliApi.appUserId + "'", "RECID");
            GridView1.DataSource = uc.MyTable;
            GridView1.DataBind();
            TextBox1.Text = uc.cbusercataid.ToString();
            TextBox2.Text = uc.cbcataid.ToString();
            TextBox3.Text = uc.jcdesc.ToString();
            Label_recid.Text = uc.RECID.ToString();
        }
        private void bind11()
        {
            cbusercata uc = cbusercata.Find(" cbuserid = '" + AliApi.appUserId + "'", "RECID");
            GridView1.DataSource = uc.MyTable;
            GridView1.DataBind();
        }
        private void dealrequest()
        {
            if (AliApi.appUserId == "")
            {
                Response.Redirect("default.aspx");
            }
            HyperLink_default.NavigateUrl = "blogmanage.aspx?userid=" + AliApi.appDomainID;
        }

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            
        }

        protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
        {
            string id = GridView1.DataKeys[e.NewSelectedIndex].Value.ToString();
            cbusercata uc = cbusercata.Find(" recid = '" + id + "'", "RECID");

            TextBox1.Text = uc.cbusercataid.ToString();
            TextBox2.Text = uc.cbcataid.ToString();
            TextBox3.Text = uc.jcdesc.ToString();
            Label_recid.Text = uc.RECID.ToString();

        }

        protected void GridView1_RowDeleted(object sender, GridViewDeletedEventArgs e)
        {
           
        }

        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string id = GridView1.DataKeys[e.RowIndex].Value.ToString();
            cbusercata uc = cbusercata.Find(" recid = '" + id + "'", "RECID");
            uc.Delete();
            bind1();
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (Label_recid.Text != "" && Label_recid.Text != "0")
            {
                cbusercata uc = cbusercata.Find(" recid = '" + Label_recid.Text + "'", "RECID");
                uc.cbusercataid.Value = TextBox1.Text;
                uc.cbcataid.Value = TextBox2.Text;
                uc.jcdesc.Value = TextBox3.Text;
                uc.Modify();
                bind11();
            }
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            if (TextBox1.Text != "" && TextBox2.Text != "" && TextBox2.Text != "0")
            {
                cbusercata uc = cbusercata.Find(" 1=2 ");
                uc.New();
                uc.cbuserid.Value = AliApi.appUserId;
                uc.cbusercataid.Value = TextBox1.Text;
                uc.cbcataid.Value = TextBox2.Text;
                uc.cbname.Value = TextBox1.Text;
                uc.jcdesc.Value = TextBox3.Text;
                uc.cblayer.Value = 1;
                uc.cbstatus.Value = "有效";
                uc.Insert();
                bind1();
            }
        }

        protected void Button_sel_Click(object sender, EventArgs e)
        {
            ScriptManager.RegisterStartupScript(this.Button_sel, this.Button_sel.GetType(), "selectbuttonclick",
        "<script type =\"text/javascript\" >selectButtonClick('" + this.TextBox2.ClientID + "');</script>", false);
        }
    }
}
